package com.chenchao.net;

import java.io.*;
import java.net.Socket;

/**
 * @encoding : UTF-8
 * @Time : 2020/11/26 10:52
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.net.Test12B.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * TCP上传客户端
 */
public class Test12B {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 10000);
        /*新建socket对象*/
        BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("myjava01/src/img/gg.jpg"));
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));

        byte[] bytes = new byte[1024];
        int len;


        /*本地流读入*/
        while ((len = bis.read(bytes)) != -1) {
            /*写入网络流*/
            bos.write(bytes, 0, len);
        }

        socket.shutdownOutput();

        /*网络流读出*/
        String s;
        while ((s = br.readLine()) != null) {
            System.out.println(s);
        }
        /*关闭资源*/
        bis.close();
        br.close();
        socket.close();

    }
}
